/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.fill;

import com.wttech.dzzf.process.dao.FillMissingDataDao;
import com.wttech.dzzf.process.dao.TransferUserInfoDao;
import com.wttech.dzzf.process.model.Organization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 填充组织机构信息
 *
 * @author MaShibo
 * @date 2017/12/13.
 */
@Service
public class FillOrganizationInfoService {

	private static final Logger LOGGER = LoggerFactory.getLogger(FillOrganizationInfoService.class);

	@Resource
	private FillMissingDataDao fillMissingDataDao;

	@Resource
	private TransferUserInfoDao transferUserInfoDao;

	private void process() {
		List<Organization> orgs = fillMissingDataDao.queryTestOrgInfos();
		orgs.forEach(organization -> {
			try {
				transferUserInfoDao.updateDzzfObject(organization);
				LOGGER.info("更新成功");
			} catch (Exception e) {
				LOGGER.error(e.getMessage(), e);
			}
		});
	}

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		FillOrganizationInfoService service = context.getBean(FillOrganizationInfoService.class);
		service.process();
	}
}
